package cn.itcast.hotel.mq;


import cn.itcast.hotel.constants.MqConstants;
import cn.itcast.hotel.service.IHotelService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class HotelListener {

    @Autowired
    private IHotelService hotelService;

    /**
     * 监听酒店新增或修改的业务
     * @param hotelId
     */
    @RabbitListener(queues = MqConstants.INSERT_QUEUE_NAME)
    public void listenHotelInsert(Long hotelId) throws IOException {
        // 新增
        hotelService.saveById(hotelId);
    }

    /**
     * 监听酒店删除的业务
     * @param hotelId
     */
    @RabbitListener(queues = MqConstants.DELETE_QUEUE_NAME)
    public void listenHotelDelete(Long hotelId) throws IOException {
        // 删除
        hotelService.deleteById(hotelId);
    }
}
